const fs = require('fs')
const path = require('path')
const { promisify } = require('util')
const op = require('sequelize').Op
// const dbLauncher = require('./db_launcher')

const db = {}
const dbPath = path.join(__dirname, '../test/test.json')
const readFile = promisify(fs.readFile)

// 获取所有列表
// filter 接收一个 item 参数，进行过滤操作

db.getFactors = async (filters = null, paging = null) => {
  const dataStr = await readFile(dbPath, 'utf8')
  const data = JSON.parse(dataStr)
  if (filters) {
  }
  if (paging) {
  }
  return data
}

db.getFactorsById = async (id) => {
  const dataStr = await readFile(dbPath, 'utf8')
  const data = JSON.parse(dataStr)
  console.log(data)
  return data.find((factor) => factor.id === Number.parseInt(id))
}

module.exports = db
